<?php

namespace App\Http\Controllers;

use App\Article;
use Illuminate\Http\Request;

class ArticlesController extends Controller
{       
      //操作
      //查看数据
      public function articles() {
        $articles = Article::all();
        return view('articles.article',compact('articles'));
      }

       //添加数据操作
       public function create(Request $request) {
        $input = $request->all();
        $user = Article::create($input);
        if($user) {
          return redirect('article');
        } else {
          return back();        
        }
      }
      
      //查看单条数据
      public function show($id) {
        $article = Article::find($id);
        return view('articles.show',compact('article'));
      }
      
     
      //
      public function update(Request $request) {
        $id = $request->input('id');
        $content = $request->input('content');
        $title = $request->input('title');
        
        $flight = Article::find($id);
        $flight->content = $content;
        $flight->title = $title;
        $isres = $flight->save();
        return $isres;
      }
      //
      public function delete(Request $request) {
        $id = $request->input('id');
        $flight = Article::find($id);
        $isres = $flight->delete();
        return $isres;
      }


    //页面
    public function add() {
      return view('articles.addArticle');
    }

    public function edit() {
      return view('articles.addArticle');
    }


 

}
